/*
 * Copyright (c) 2012 Universidad Antonio de Nebrija.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * Contributors:
 *    Universidad Antonio de Nebrija - initial API, implementation and documentation
 */
package com.nebrija.riif.model.functions;

import com.nebrija.riif.model.Function;
import com.nebrija.riif.model.Util;

/**
 * Represents the x^y function
 * @author asanchep
 *
 */
public class PowFunction extends Function{

	/** function name */
	public static final String NAME="pow";
	
	/**
	 * Creates an EXPFunction
	 */
	public PowFunction() {
		super(PowFunction.NAME, 2);
	}

	@Override
	protected Object executeFunction(Object... operands) {
		Object op1 = operands[0];
		Object op2 = operands[1];
		
		// If the operand is a string, we could not compute it. Return the original function
		if(op1 instanceof String || op2 instanceof String){
			return NAME+"("+op1+","+op2+")";
		}
		
		//Return operand[0]^operands[1]
		return Math.pow(Util.convertToDouble(op1),Util.convertToDouble(op2));
	}

}
